#include <bits/stdc++.h>
using namespace std;
const int Maxn= 1e6+10;
struct car
{
    int d,v0,a_;
}w[Maxn/10];
int qt,qd;
int T,n,m,L,vmax;
int carnum=0,detnum=0;
int wp[Maxn/10];
vector<int> ov[Maxn/10];
void outov()
{
    for(int i=1;i<=n;++i)
    {
        for(int j=0;j<ov[i].size();++j)
        {
            cout<<ov[i][j]<<' ';
        }
        cout<<endl;
    }
}
void speed()
{
    for(int i=1;i<=n;++i)
    {
        int start=w[i].d;
        int v=w[i].v0;
        int a=w[i].a_;
        int j=1;
        while(j<=m)
        {
            while(wp[j]<start && j<=m) j++;
            if(j>m) break;
            if(wp[j]==start)
            {
                if(vmax>v) ov[i].push_back(wp[j]);
                //cout<<0<<endl;
            }
            else if(wp[j]>start && vmax*vmax>v*v+2*a*(wp[j]-start))
            {
                //cout<<j<<endl;
                ov[i].push_back(wp[j]);
            }
            j++;
        }
    }
}
void judge()
{
    for(int i=1;i<=n;i++)
    {
        if(ov[i].empty()) continue;
        carnum++;
    }
    int top_=Maxn,tal_=0;
    for(int i=1;i<=n;++i)
    {
        if(!ov[i].empty())
        {
            if(w[i].a_>=0)
            {

            }
            else
            {

            }
        }
    }
}
signed main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    memset(wp,0,sizeof(wp));
    memset(ov,0,sizeof(ov));
    cin>>T;
    for(int i=1;i<=T;++i)
    {
        cin>>n>>m>>L>>vmax;
        for(int j=1;j<=n;++j)
        {
            cin>>w[i].d>>w[i].v0>>w[i].a_;
        }
        for(int j=1;j<=m;++j)
        {
            int p;
            cin>>p;
            wp[j]=p;
        }
        speed();
        outov();
        judge();
        if(i==T)
        {
            cout<<carnum<<' '<<detnum<<endl;
            return 0;
        }
        else
        {
            cout<<carnum<<' '<<detnum<<endl;
            carnum=0;
            detnum=0;
            memset(wp,0,sizeof(wp));
            memset(ov,0,sizeof(ov));
            memset(w,0,sizeof(w));
        }
    }
    return 0;
}
